//添加
import React, { useState } from 'react';
import {
    Button,
    DatePicker,
    Form,
    Input,
    message,

} from 'antd';
import { addSpecial } from '../../../../../api/csy/api'

const formItemLayout = {
    labelCol: {
        xs: { span: 24 },
        sm: { span: 6 },
    },
    wrapperCol: {
        xs: { span: 24 },
        sm: { span: 14 },
    },
};

import { Select, Space } from 'antd';
import { useNavigate } from 'react-router-dom';



const App: React.FC = () => {
    const [form] = Form.useForm();
    const [title, setTitle] = useState<string>('')
    const [year, setYear] = useState<string>('')
    const [name1, setName] = useState<string>('')
    const [jianTime, setJianTime] = useState<string>('')
    const [rusult, setRusult] = useState<string>('')

    const navigate = useNavigate()
    const dian = () => {
        addSpecial({
            year: year,
            title: title,
            name: name1,
            time: jianTime,
            rusult: rusult,
        }).then((res) => {
            if (res.data.code == 200) {
                navigate('/service/Operational/security/indexSpecial/specialInspection')
                message.success('添加成功')
                setTitle('')
                setYear('')
                setName('')
                setJianTime('')
                setRusult('')
            }
        })
    }

    const handleChange = (value: string) => {
        setRusult(value)
    };

    return (
        <Form
            {...formItemLayout}
            form={form}
            style={{ maxWidth: 600 }}
        >
            <Form.Item label="检查主题" name="title" rules={[{ required: true, message: 'Please input!' }]}>
                <Input value={title} onChange={(e) => setTitle(e.target.value)} />
            </Form.Item>
            <Form.Item label="年份" name="year" rules={[{ required: true, message: 'Please input!' }]}>
                <Input value={year} onChange={(e) => setYear(e.target.value)} />
            </Form.Item>
            <Form.Item label="任务下达人" name="name1" rules={[{ required: true, message: 'Please input!' }]}>
                <Input value={name1} onChange={(e) => setName(e.target.value)} />
            </Form.Item>
            <Form.Item
                label="检查时间"
                name="jianTime"
                rules={[{ required: true, message: 'Please input!' }]}
            >
                <DatePicker onChange={(e) => setJianTime(e as unknown as string)} />
            </Form.Item>
            <Form.Item
                label="检查结果"
                name="rusult"
                rules={[{ required: true, message: 'Please input!' }]}
            >
                <Select
                    defaultValue="正常"
                    style={{ width: 120 }}
                    onChange={handleChange}
                    options={[
                        { value: '正常', label: '正常' },
                        { value: '隐患', label: '隐患' },
                    ]}
                />
            </Form.Item>
            <Form.Item wrapperCol={{ offset: 6, span: 16 }}>
                <Button type="primary" htmlType="submit" onClick={dian}>
                    Submit
                </Button>
            </Form.Item>
        </Form>
    );
};

export default App;